<a href='https://github.com/angular/angular.js/edit/v1.5.x/docs/content/misc/contribute.ngdoc?message=docs(misc%2FDevelop)%3A%20describe%20your%20change...' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>


<h1 id="building-and-testing-angularjs">Building and Testing AngularJS</h1>
<p>This document describes how to set up your development environment to build and test AngularJS, and
explains the basic mechanics of using <code>git</code>, <code>node</code>, <code>npm</code>, <code>grunt</code>, and <code>bower</code>.</p>
<p>See the <a href="https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md">contributing guidelines</a>
for how to contribute your own code to AngularJS.</p>
<ol>
<li><a href="misc/contribute#installing-dependencies">Installing Dependencies</a></li>
<li><a href="misc/contribute#forking-angular-on-github">Forking Angular on Github</a></li>
<li><a href="misc/contribute#building-angularjs">Building AngularJS</a></li>
<li><a href="misc/contribute#running-a-local-development-web-server">Running a Local Development Web Server</a></li>
<li><a href="misc/contribute#running-the-unit-test-suite">Running the Unit Test Suite</a></li>
<li><a href="misc/contribute#running-the-end-to-end-test-suite">Running the End-to-end Test Suite</a></li>
</ol>
<h2 id="installing-dependencies">Installing Dependencies</h2>
<p>Before you can build AngularJS, you must install and configure the following dependencies on your
machine:</p>
<ul>
<li><p><a href="http://git-scm.com/">Git</a>: The <a href="https://help.github.com/articles/set-up-git">Github Guide to
Installing Git</a> is a good source of information.</p>
</li>
<li><p><a href="http://nodejs.org">Node.js v4.x</a>: We use Node to generate the documentation, run a
development web server, run tests, and generate distributable files. Depending on your system, you can install Node either from source or as a
pre-packaged bundle. (Currently our build does not work properly on Node v5 or greater - please use v4.x.)</p>
</li>
<li><p><a href="http://www.java.com">Java</a>: We minify JavaScript using our
<a href="https://developers.google.com/closure/">Closure Tools</a> jar. Make sure you have Java (version 7 or higher) installed
and included in your <a href="http://docs.oracle.com/javase/tutorial/essential/environment/paths.html">PATH</a> variable.</p>
</li>
<li><p><a href="http://gruntjs.com">Grunt</a>: We use Grunt as our build system. Install the grunt command-line tool globally with:</p>
<pre><code class="lang-shell">npm install -g grunt-cli
</code></pre>
</li>
</ul>
<h2 id="forking-angular-on-github">Forking Angular on Github</h2>
<p>To create a Github account, follow the instructions <a href="https://github.com/signup/free">here</a>.
Afterwards, go ahead and <a href="http://help.github.com/forking">fork</a> the <a href="https://github.com/angular/angular.js">main AngularJS repository</a>.</p>
<h2 id="building-angularjs">Building AngularJS</h2>
<p>To build AngularJS, you clone the source code repository and use Grunt to generate the non-minified and
minified AngularJS files:</p>
<pre><code class="lang-shell"># Clone your Github repository:
git clone https://github.com/&lt;github username&gt;/angular.js.git

# Go to the AngularJS directory:
cd angular.js

# Add the main AngularJS repository as an upstream remote to your repository:
git remote add upstream &quot;https://github.com/angular/angular.js.git&quot;

# Install node.js dependencies:
npm install

# Install bower components:
bower install

# Build AngularJS:
grunt package
</code></pre>
<div class="alert alert-warning">
<strong>Note:</strong> If you&#39;re using Windows, you must use an elevated command prompt (right click, run as
Administrator). This is because <code>grunt package</code> creates some symbolic links.
</div>

<div class="alert alert-warning">
<strong>Note:</strong> If you&#39;re using Linux, and npm install fails with the message
&#39;Please try running this command again as root/Administrator.&#39;, you may need to globally install grunt and bower:
<ul>
<li>sudo npm install -g grunt-cli</li>
<li>sudo npm install -g bower</li>
</ul>

</div>

<p>The build output can be located under the <code>build</code> directory. It consists of the following files and
directories:</p>
<ul>
<li><p><code>angular-&lt;version&gt;.zip</code> — The complete zip file, containing all of the release build
artifacts.</p>
</li>
<li><p><code>angular.js</code> — The non-minified <code>angular</code> script.</p>
</li>
<li><p><code>angular.min.js</code> —  The minified <code>angular</code> script.</p>
</li>
<li><p><code>angular-scenario.js</code> — The <code>angular</code> End2End test runner.</p>
</li>
<li><p><code>docs/</code> — A directory that contains all of the files needed to run <code>docs.angularjs.org</code>.</p>
</li>
<li><p><code>docs/index.html</code> — The main page for the documentation.</p>
</li>
<li><p><code>docs/docs-scenario.html</code> — The End2End test runner for the documentation application.</p>
</li>
</ul>
<h2 id="running-a-local-development-web-server">Running a Local Development Web Server</h2>
<p>To debug code and run end-to-end tests, it is often useful to have a local HTTP server. For this purpose, we have
made available a local web server based on Node.js.</p>
<ol>
<li><p>To start the web server, run:</p>
<pre><code class="lang-shell">grunt webserver
</code></pre>
</li>
<li><p>To access the local server, enter the following URL into your web browser:</p>
<pre><code class="lang-text">http://localhost:8000/
</code></pre>
<p>By default, it serves the contents of the AngularJS project directory.</p>
</li>
<li><p>To access the locally served docs, visit this URL:</p>
<pre><code class="lang-text">http://localhost:8000/build/docs/
</code></pre>
</li>
</ol>
<h2 id="running-the-unit-test-suite">Running the Unit Test Suite</h2>
<p>We write unit and integration tests with Jasmine and execute them with Karma. To run all of the
tests once on Chrome run:</p>
<pre><code class="lang-shell">grunt test:unit
</code></pre>
<p>To run the tests on other browsers (Chrome, ChromeCanary, Firefox, Opera and Safari are pre-configured) use:</p>
<pre><code class="lang-shell">grunt test:unit --browsers Opera,Firefox
</code></pre>
<p>Note there should be <em>no spaces between browsers</em>. <code>Opera, Firefox</code> is INVALID.</p>
<p>During development, however, it&#39;s more productive to continuously run unit tests every time the source or test files
change. To execute tests in this mode run:</p>
<ol>
<li><p>To start the Karma server, capture Chrome browser and run unit tests, run:</p>
<pre><code class="lang-shell">grunt autotest
</code></pre>
</li>
<li><p>To capture more browsers, open this URL in the desired browser (URL might be different if you have multiple instance
of Karma running, read Karma&#39;s console output for the correct URL):</p>
<pre><code class="lang-text">http://localhost:9876/
</code></pre>
</li>
<li><p>To re-run tests just change any source or test file.</p>
</li>
</ol>
<p>To learn more about all of the preconfigured Grunt tasks run:</p>
<pre><code class="lang-shell">grunt --help
</code></pre>
<h2 id="running-the-end-to-end-test-suite">Running the End-to-end Test Suite</h2>
<p>Angular&#39;s end to end tests are run with Protractor. Simply run:</p>
<pre><code class="lang-shell">grunt test:e2e
</code></pre>
<p>This will start the webserver and run the tests on Chrome.</p>


